• frmBusFeePayment_Student.vb
  • project /
1 Imports System.Data.SqlClient
2 Imports System.IO
3
4 Public Class frmBusFeePayment_Student
5     Sub Calculate()
6         Dim num1, num2 As Double
7         num1 = CDbl(Val(txtBusFee.Text) + Val(txtFine.Text) + Val(txtPreviousDue.Text) - Val(txtDiscount.Text))
8         num1 = Math.Round(num1,
2)
9         txtGrandTotal.Text = num1
10         num2 = Val(txtGrandTotal.Text) - Val(txtTotalPaid.Text)
11         num2 = Math.Round(num2,
2)
12         txtBalance.Text = num2
13     End Sub
14     Sub Print()
15         Try
16             Cursor = Cursors.WaitCursor
17             Timer1.Enabled = True
18             Dim rpt As New rptBusFeeReceipt_Student
'The report you created.
19             Dim myConnection As SqlConnection
20             Dim MyCommand As New SqlCommand()
21             Dim myDA As New SqlDataAdapter()
22             Dim myDS As New DataSet
'The DataSet you created.
23             myConnection = New SqlConnection(cs)
24             MyCommand.Connection = myConnection
25             MyCommand.CommandText =
"SELECT SchoolInfo.S_Id, SchoolInfo.SchoolName, SchoolInfo.Address, SchoolInfo.ContactNo, SchoolInfo.AltContactNo, SchoolInfo.FaxNo, SchoolInfo.Email, SchoolInfo.Website, SchoolInfo.Logo, SchoolInfo.RegistrationNo,SchoolInfo.DiseNo, SchoolInfo.IndexNo, SchoolInfo.EstablishedYear, Student.AdmissionNo, Student.EnrollmentNo, Student.GRNo, Student.UID, Student.StudentName,Student.FatherName, Student.MotherName, Student.FatherCN, Student.PermanentAddress, Student.TemporaryAddress, Student.EmailID, Student.DOB, Student.Gender,Student.AdmissionDate, Student.Caste, Student.Religion, Student.SectionID, Student.Photo, Student.Nationality, Student.SchoolID, Student.LastSchoolAttended, Student.Result,Student.PassPercentage, Student.Status, BusCardHolder_Student.BCH_Id, BusCardHolder_Student.AdmissionNo AS Expr2, BusCardHolder_Student.BusNo, BusCardHolder_Student.Location,BusCardHolder_Student.JoiningDate, BusFeePayment_Student.Id, BusFeePayment_Student.BFP_ID, BusFeePayment_Student.PaymentID,BusFeePayment_Student.BusHolderID, BusFeePayment_Student.Session , BusFeePayment_Student.Installment, BusFeePayment_Student.TotalFee, BusFeePayment_Student.DiscountPer,BusFeePayment_Student.DiscountAmt, BusFeePayment_Student.PreviousDue, BusFeePayment_Student.Fine, BusFeePayment_Student.GrandTotal, BusFeePayment_Student.TotalPaid,BusFeePayment_Student.ModeOfPayment, BusFeePayment_Student.PaymentModeDetails, BusFeePayment_Student.PaymentDate, BusFeePayment_Student.PaymentDue, BusFeePayment_Student.ClassType,BusFeePayment_Student.SchoolType , BusFeePayment_Student.Class , BusFeePayment_Student.Section FROM SchoolInfo INNER JOIN Student ON SchoolInfo.S_Id = Student.SchoolID INNER JOIN BusCardHolder_Student ON Student.AdmissionNo = BusCardHolder_Student.AdmissionNo INNER JOIN BusFeePayment_Student ON BusCardHolder_Student.BCH_Id = BusFeePayment_Student.BusHolderID where PaymentID='" & txtFeePaymentID.Text & "'"
26             MyCommand.CommandType = CommandType.Text
27             myDA.SelectCommand = MyCommand
28             myDA.Fill(myDS,
"Student")
29             myDA.Fill(myDS,
"BusCardHolder_Student")
30             myDA.Fill(myDS,
"SchoolInfo")
31             myDA.Fill(myDS,
"BusFeePayment_Student")
32             rpt.SetDataSource(myDS)
33             frmReport.CrystalReportViewer1.ReportSource = rpt
34             frmReport.ShowDialog()
35         Catch ex As Exception
36             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
37         End Try
38     End Sub
39     Private Function GenerateID() As String
40         con = New SqlConnection(cs)
41         Dim
value As String = "0000"
42         Try
43             
' Fetch the latest ID from the database
44             con.Open()
45             cmd = New SqlCommand(
"SELECT TOP 1 (BFP_ID) FROM BusFeePayment_Student where ClassType='Nursery' and SchoolType='English' ORDER BY BFP_ID DESC", con)
46             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
47             If rdr.HasRows Then
48                 rdr.Read()
49                 
value = rdr.Item("BFP_ID")
50             End If
51             rdr.Close()
52             
' Increase the ID by 1
53             
value += 1
54             
' Because incrementing a string with an integer removes 0's
55             
' we need to replace them. If necessary.
56             If
value <= 9 Then 'Value is between 0 and 10
57                 
value = "000" & value
58             ElseIf
value <= 99 Then 'Value is between 9 and 100
59                 
value = "00" & value
60             ElseIf
value <= 999 Then 'Value is between 999 and 1000
61                 
value = "0" & value
62             End If
63         Catch ex As Exception
64             
' If an error occurs, check the connection state and close it if necessary.
65             If con.State = ConnectionState.Open Then
66                 con.Close()
67             End If
68             
value = "0000"
69         End Try
70         Return
value
71     End Function
72     Public Sub auto()
73         Try
74             txtBFPId.Text = GenerateID()
75             Dim a As String = txtAdmissionNo.Text
76             txtFeePaymentID.Text =
"EBFN-" + GenerateID() + "-" + a
77         Catch ex As Exception
78             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
79         End Try
80     End Sub
81     Private Function GenerateID1() As String
82         con = New SqlConnection(cs)
83         Dim
value As String = "0000"
84         Try
85             
' Fetch the latest ID from the database
86             con.Open()
87             cmd = New SqlCommand(
"SELECT TOP 1 (BFP_ID) FROM BusFeePayment_Student where ClassType='Primary' and SchoolType='English' ORDER BY BFP_ID DESC", con)
88             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
89             If rdr.HasRows Then
90                 rdr.Read()
91                 
value = rdr.Item("BFP_ID")
92             End If
93             rdr.Close()
94             
' Increase the ID by 1
95             
value += 1
96             
' Because incrementing a string with an integer removes 0's
97             
' we need to replace them. If necessary.
98             If
value <= 9 Then 'Value is between 0 and 10
99                 
value = "000" & value
100             ElseIf
value <= 99 Then 'Value is between 9 and 100
101                 
value = "00" & value
102             ElseIf
value <= 999 Then 'Value is between 999 and 1000
103                 
value = "0" & value
104             End If
105         Catch ex As Exception
106             
' If an error occurs, check the connection state and close it if necessary.
107             If con.State = ConnectionState.Open Then
108                 con.Close()
109             End If
110             
value = "0000"
111         End Try
112         Return
value
113     End Function
114     Sub auto1()
115         Try
116             txtBFPId.Text = GenerateID1()
117             Dim a As String = txtAdmissionNo.Text
118             txtFeePaymentID.Text =
"EBFP-" + GenerateID1() + "-" + a
119         Catch ex As Exception
120             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
121         End Try
122     End Sub
123     Private Function GenerateID2() As String
124         con = New SqlConnection(cs)
125         Dim
value As String = "0000"
126         Try
127             
' Fetch the latest ID from the database
128             con.Open()
129             cmd = New SqlCommand(
"SELECT TOP 1 (BFP_ID) FROM BusFeePayment_Student where ClassType='Secondary' and SchoolType='English' ORDER BY BFP_ID DESC", con)
130             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
131             If rdr.HasRows Then
132                 rdr.Read()
133                 
value = rdr.Item("BFP_ID")
134             End If
135             rdr.Close()
136             
' Increase the ID by 1
137             
value += 1
138             
' Because incrementing a string with an integer removes 0's
139             
' we need to replace them. If necessary.
140             If
value <= 9 Then 'Value is between 0 and 10
141                 
value = "000" & value
142             ElseIf
value <= 99 Then 'Value is between 9 and 100
143                 
value = "00" & value
144             ElseIf
value <= 999 Then 'Value is between 999 and 1000
145                 
value = "0" & value
146             End If
147         Catch ex As Exception
148             
' If an error occurs, check the connection state and close it if necessary.
149             If con.State = ConnectionState.Open Then
150                 con.Close()
151             End If
152             
value = "0000"
153         End Try
154         Return
value
155     End Function
156     Sub auto2()
157         Try
158             txtBFPId.Text = GenerateID2()
159             Dim a As String = txtAdmissionNo.Text
160             txtFeePaymentID.Text =
"EBFS-" + GenerateID2() + "-" + a
161         Catch ex As Exception
162             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
163         End Try
164     End Sub
165     Private Function GenerateID3() As String
166         con = New SqlConnection(cs)
167         Dim
value As String = "0000"
168         Try
169             
' Fetch the latest ID from the database
170             con.Open()
171             cmd = New SqlCommand(
"SELECT TOP 1 (BFP_ID) FROM BusFeePayment_Student where ClassType='Higher Secondary' and SchoolType='English' ORDER BY BFP_ID DESC", con)
172             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
173             If rdr.HasRows Then
174                 rdr.Read()
175                 
value = rdr.Item("BFP_ID")
176             End If
177             rdr.Close()
178             
' Increase the ID by 1
179             
value += 1
180             
' Because incrementing a string with an integer removes 0's
181             
' we need to replace them. If necessary.
182             If
value <= 9 Then 'Value is between 0 and 10
183                 
value = "000" & value
184             ElseIf
value <= 99 Then 'Value is between 9 and 100
185                 
value = "00" & value
186             ElseIf
value <= 999 Then 'Value is between 999 and 1000
187                 
value = "0" & value
188             End If
189         Catch ex As Exception
190             
' If an error occurs, check the connection state and close it if necessary.
191             If con.State = ConnectionState.Open Then
192                 con.Close()
193             End If
194             
value = "0000"
195         End Try
196         Return
value
197     End Function
198     Sub auto3()
199         Try
200             txtBFPId.Text = GenerateID3()
201             Dim a As String = txtAdmissionNo.Text
202             txtFeePaymentID.Text =
"EBFHS-" + GenerateID3() + "-" + a
203         Catch ex As Exception
204             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
205         End Try
206     End Sub
207     Private Function GenerateID4() As String
208         con = New SqlConnection(cs)
209         Dim
value As String = "0000"
210         Try
211             
' Fetch the latest ID from the database
212             con.Open()
213             cmd = New SqlCommand(
"SELECT TOP 1 (BFP_ID) FROM BusFeePayment_Student where ClassType='Nursery' and SchoolType='Gujarati' ORDER BY BFP_ID DESC", con)
214             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
215             If rdr.HasRows Then
216                 rdr.Read()
217                 
value = rdr.Item("BFP_ID")
218             End If
219             rdr.Close()
220             
' Increase the ID by 1
221             
value += 1
222             
' Because incrementing a string with an integer removes 0's
223             
' we need to replace them. If necessary.
224             If
value <= 9 Then 'Value is between 0 and 10
225                 
value = "000" & value
226             ElseIf
value <= 99 Then 'Value is between 9 and 100
227                 
value = "00" & value
228             ElseIf
value <= 999 Then 'Value is between 999 and 1000
229                 
value = "0" & value
230             End If
231         Catch ex As Exception
232             
' If an error occurs, check the connection state and close it if necessary.
233             If con.State = ConnectionState.Open Then
234                 con.Close()
235             End If
236             
value = "0000"
237         End Try
238         Return
value
239     End Function
240     Sub auto4()
241         Try
242             txtBFPId.Text = GenerateID4()
243             Dim a As String = txtAdmissionNo.Text
244             txtFeePaymentID.Text =
"GBFN-" + GenerateID4() + "-" + a
245         Catch ex As Exception
246             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
247         End Try
248     End Sub
249     Private Function GenerateID5() As String
250         con = New SqlConnection(cs)
251         Dim
value As String = "0000"
252         Try
253             
' Fetch the latest ID from the database
254             con.Open()
255             cmd = New SqlCommand(
"SELECT TOP 1 (BFP_ID) FROM BusFeePayment_Student where ClassType='Primary' and SchoolType='Gujarati' ORDER BY BFP_ID DESC", con)
256             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
257             If rdr.HasRows Then
258                 rdr.Read()
259                 
value = rdr.Item("BFP_ID")
260             End If
261             rdr.Close()
262             
' Increase the ID by 1
263             
value += 1
264             
' Because incrementing a string with an integer removes 0's
265             
' we need to replace them. If necessary.
266             If
value <= 9 Then 'Value is between 0 and 10
267                 
value = "000" & value
268             ElseIf
value <= 99 Then 'Value is between 9 and 100
269                 
value = "00" & value
270             ElseIf
value <= 999 Then 'Value is between 999 and 1000
271                 
value = "0" & value
272             End If
273         Catch ex As Exception
274             
' If an error occurs, check the connection state and close it if necessary.
275             If con.State = ConnectionState.Open Then
276                 con.Close()
277             End If
278             
value = "0000"
279         End Try
280         Return
value
281     End Function
282     Sub auto5()
283         Try
284             txtBFPId.Text = GenerateID5()
285             Dim a As String = txtAdmissionNo.Text
286             txtFeePaymentID.Text =
"GBFP-" + GenerateID5() + "-" + a
287         Catch ex As Exception
288             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
289         End Try
290     End Sub
291     Private Function GenerateID6() As String
292         con = New SqlConnection(cs)
293         Dim
value As String = "0000"
294         Try
295             
' Fetch the latest ID from the database
296             con.Open()
297             cmd = New SqlCommand(
"SELECT TOP 1 (BFP_ID) FROM BusFeePayment_Student where ClassType='Secondary' and SchoolType='Gujarati' ORDER BY BFP_ID DESC", con)
298             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
299             If rdr.HasRows Then
300                 rdr.Read()
301                 
value = rdr.Item("BFP_ID")
302             End If
303             rdr.Close()
304             
' Increase the ID by 1
305             
value += 1
306             
' Because incrementing a string with an integer removes 0's
307             
' we need to replace them. If necessary.
308             If
value <= 9 Then 'Value is between 0 and 10
309                 
value = "000" & value
310             ElseIf
value <= 99 Then 'Value is between 9 and 100
311                 
value = "00" & value
312             ElseIf
value <= 999 Then 'Value is between 999 and 1000
313                 
value = "0" & value
314             End If
315         Catch ex As Exception
316             
' If an error occurs, check the connection state and close it if necessary.
317             If con.State = ConnectionState.Open Then
318                 con.Close()
319             End If
320             
value = "0000"
321         End Try
322         Return
value
323     End Function
324     Sub auto6()
325         Try
326             txtBFPId.Text = GenerateID6()
327             Dim a As String = txtAdmissionNo.Text
328             txtFeePaymentID.Text =
"GBFS-" + GenerateID6() + "-" + a
329         Catch ex As Exception
330             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
331         End Try
332     End Sub
333     Private Function GenerateID7() As String
334         con = New SqlConnection(cs)
335         Dim
value As String = "0000"
336         Try
337             
' Fetch the latest ID from the database
338             con.Open()
339             cmd = New SqlCommand(
"SELECT TOP 1 (BFP_ID) FROM BusFeePayment_Student where ClassType='Higher Secondary' and SchoolType='Gujarati' ORDER BY BFP_ID DESC", con)
340             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
341             If rdr.HasRows Then
342                 rdr.Read()
343                 
value = rdr.Item("BFP_ID")
344             End If
345             rdr.Close()
346             
' Increase the ID by 1
347             
value += 1
348             
' Because incrementing a string with an integer removes 0's
349             
' we need to replace them. If necessary.
350             If
value <= 9 Then 'Value is between 0 and 10
351                 
value = "000" & value
352             ElseIf
value <= 99 Then 'Value is between 9 and 100
353                 
value = "00" & value
354             ElseIf
value <= 999 Then 'Value is between 999 and 1000
355                 
value = "0" & value
356             End If
357         Catch ex As Exception
358             
' If an error occurs, check the connection state and close it if necessary.
359             If con.State = ConnectionState.Open Then
360                 con.Close()
361             End If
362             
value = "0000"
363         End Try
364         Return
value
365     End Function
366     Sub auto7()
367         Try
368             txtBFPId.Text = GenerateID7()
369             Dim a As String = txtAdmissionNo.Text
370             txtFeePaymentID.Text =
"GBFHS-" + GenerateID7() + "-" + a
371         Catch ex As Exception
372             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
373         End Try
374     End Sub
375     Sub Reset()
376         cmbInstallment.DropDownStyle = ComboBoxStyle.DropDownList
377         txtAdmissionNo.Text =
""
378         txtBusFee.Text =
""
379         txtPaymentModeDetails.Text =
""
380         txtBalance.Text =
""
381         txtClass.Text =
""
382         txtDiscount.Text =
""
383         txtDiscountPer.Text =
""
384         txtEnrollmentNo.Text =
""
385         txtFine.Text =
""
386         txtGrandTotal.Text =
""
387         txtPreviousDue.Text =
""
388         txtLocation.Text =
""
389         txtSection.Text =
""
390         txtSession.Text =
""
391         txtStudentName.Text =
""
392         txtTotalPaid.Text =
""
393         txtClassType.Text =
""
394         txtSchoolType.Text =
""
395         cmbPaymentMode.SelectedIndex = -
1
396         cmbInstallment.SelectedIndex = -
1
397         dtpPaymentDate.Text = Now
398         btnSave.Enabled = True
399         cmbInstallment.Enabled = True
400         btnUpdate.Enabled = False
401         btnDelete.Enabled = False
402         btnPrint.Enabled = False
403         Button2.Enabled = True
404         dtpPaymentDate.Enabled = True
405     End Sub
406     Sub FillData()
407         Try
408             con = New SqlConnection(cs)
409             con.Open()
410             cmd = con.CreateCommand()
411             cmd.CommandText =
"SELECT Type FROM ClassType,Class where ClassType.Type=Class.ClassType and Classname=@d1"
412             cmd.Parameters.AddWithValue(
"@d1", txtClass.Text)
413             rdr = cmd.ExecuteReader()
414             If rdr.Read() Then
415                 txtClassType.Text = rdr.GetValue(
0).ToString().Trim()
416             End If
417             If (rdr IsNot Nothing) Then
418                 rdr.Close()
419             End If
420             If con.State = ConnectionState.Open Then
421                 con.Close()
422             End If
423             con = New SqlConnection(cs)
424             con.Open()
425             cmd = con.CreateCommand()
426             cmd.CommandText =
"SELECT Type FROM SchoolType,SchoolInfo where SchoolType.Type=SchoolInfo.SchoolType and SchoolName=@d1"
427             cmd.Parameters.AddWithValue(
"@d1", txtSchoolName.Text)
428             rdr = cmd.ExecuteReader()
429             If rdr.Read() Then
430                 txtSchoolType.Text = rdr.GetValue(
0).ToString().Trim()
431             End If
432             If (rdr IsNot Nothing) Then
433                 rdr.Close()
434             End If
435             If con.State = ConnectionState.Open Then
436                 con.Close()
437             End If
438             con = New SqlConnection(cs)
439             con.Open()
440             cmd = con.CreateCommand()
441             cmd.CommandText =
"SELECT EnrollmentNo,Session FROM Student where AdmissionNo=@d1"
442             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
443             rdr = cmd.ExecuteReader()
444             If rdr.Read() Then
445                 txtEnrollmentNo.Text = rdr.GetValue(
0).ToString().Trim()
446                 txtSession.Text = rdr.GetValue(
1).ToString().Trim()
447             End If
448             If (rdr IsNot Nothing) Then
449                 rdr.Close()
450             End If
451             If con.State = ConnectionState.Open Then
452                 con.Close()
453             End If
454         Catch ex As Exception
455             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
456         End Try
457     End Sub
458     Sub Fill()
459         Try
460             con = New SqlConnection(cs)
461             con.Open()
462             cmd = con.CreateCommand()
463             cmd.CommandText =
"SELECT Discount from Discount where AdmissionNo=@d1 and FeeType='Bus'"
464             cmd.Parameters.AddWithValue(
"@d1", txtAdmissionNo.Text)
465             rdr = cmd.ExecuteReader()
466             If rdr.Read() Then
467                 txtDiscountPer.Text = rdr.GetValue(
0)
468                 Dim num As Double
469                 num = CDbl((Val(txtBusFee.Text) * Val(txtDiscountPer.Text)) /
100)
470                 num = Math.Round(num,
2)
471                 txtDiscount.Text = num
472             End If
473             If (rdr IsNot Nothing) Then
474                 rdr.Close()
475             End If
476             If con.State = ConnectionState.Open Then
477                 con.Close()
478             End If
479
480             Calculate()
481         Catch ex As Exception
482             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
483         End Try
484     End Sub
485     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
486         frmBusCardHolder_StudentRecord.lblSet.Text =
"Bus Fee Payment"
487         frmBusCardHolder_StudentRecord.Reset()
488         frmBusCardHolder_StudentRecord.ShowDialog()
489     End Sub
490
491     Private Sub btnGetFeeList_Click(sender As System.Object, e As System.EventArgs) Handles btnGetFeeList.Click
492         Try
493             If txtAdmissionNo.Text =
"" Then
494                 MessageBox.Show(
"Please retrieve buser info", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
495                 txtAdmissionNo.Focus()
496                 Return
497             End If
498             If cmbInstallment.Text =
"" Then
499                 MessageBox.Show(
"Please select installment", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
500                 cmbInstallment.Focus()
501                 Return
502             End If
503             con = New SqlConnection(cs)
504             con.Open()
505             cmd = con.CreateCommand()
506             cmd.CommandText =
"SELECT Charges from Installment_Bus where Installment=@d1 and Location=@d2"
507             cmd.Parameters.AddWithValue(
"@d1", cmbInstallment.Text)
508             cmd.Parameters.AddWithValue(
"@d2", txtLocation.Text)
509             rdr = cmd.ExecuteReader()
510             If rdr.Read() Then
511                 txtBusFee.Text = rdr.GetValue(
0)
512             End If
513             If (rdr IsNot Nothing) Then
514                 rdr.Close()
515             End If
516             If con.State = ConnectionState.Open Then
517                 con.Close()
518             End If
519             con = New SqlConnection(cs)
520             con.Open()
521             cmd = con.CreateCommand()
522             cmd.CommandText =
"SELECT Sum(PaymentDue-PreviousDue) from BusFeePayment_Student where BusHolderID=@d1 group by BusHolderID"
523             cmd.Parameters.AddWithValue(
"@d1", txtBusHolderID.Text)
524             rdr = cmd.ExecuteReader()
525             If rdr.Read() Then
526                 txtPreviousDue.Text = rdr.GetValue(
0)
527             Else
528                 txtPreviousDue.Text =
0
529             End If
530             If (rdr IsNot Nothing) Then
531                 rdr.Close()
532             End If
533             If con.State = ConnectionState.Open Then
534                 con.Close()
535             End If
536             Fill()
537         Catch ex As Exception
538             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
539         End Try
540     End Sub
541
542     Private Sub btnNew_Click(sender As System.Object, e As System.EventArgs) Handles btnNew.Click
543         Reset()
544         Reset()
545     End Sub
546
547     Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
548         If Len(Trim(txtAdmissionNo.Text)) =
0 Then
549             MessageBox.Show(
"Please retrieve bus holder info", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
550             txtAdmissionNo.Focus()
551             Exit Sub
552         End If
553         If Len(Trim(cmbInstallment.Text)) =
0 Then
554             MessageBox.Show(
"Please select installment", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
555             cmbInstallment.Focus()
556             Exit Sub
557         End If
558         If Len(Trim(txtFine.Text)) =
0 Then
559             MessageBox.Show(
"Please enter fine", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
560             txtFine.Focus()
561             Exit Sub
562         End If
563         If Len(Trim(cmbPaymentMode.Text)) =
0 Then
564             MessageBox.Show(
"Please select Payment Mode", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
565             cmbPaymentMode.Focus()
566             Exit Sub
567         End If
568         If Len(Trim(txtTotalPaid.Text)) =
0 Then
569             MessageBox.Show(
"Please enter total paid", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
570             txtTotalPaid.Focus()
571             Exit Sub
572         End If
573         If Val(txtBalance.Text) <
0 Then
574             MessageBox.Show(
"Balance is not possible less than zero", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error)
575             Exit Sub
576         End If
577         Try
578             con = New SqlConnection(cs)
579             con.Open()
580             Dim ct As String =
"select Session,BusHolderID,Installment from BusFeePayment_Student where Session=@d1 and BusHolderID=@d2 and Installment=@d3"
581             cmd = New SqlCommand(ct)
582             cmd.Connection = con
583             cmd.Parameters.AddWithValue(
"@d1", txtSession.Text)
584             cmd.Parameters.AddWithValue(
"@d2", txtBusHolderID.Text)
585             cmd.Parameters.AddWithValue(
"@d3", cmbInstallment.Text)
586             rdr = cmd.ExecuteReader()
587             If rdr.Read Then
588                 MessageBox.Show(
"Already paid", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
589                 If Not rdr Is Nothing Then
590                     rdr.Close()
591                 End If
592                 Exit Sub
593             End If
594             If txtClassType.Text =
"Nursery" And txtSchoolType.Text = "English" Then
595                 auto()
596             End If
597             If txtClassType.Text =
"Primary" And txtSchoolType.Text = "English" Then
598                 auto1()
599             End If
600             If txtClassType.Text =
"Secondary" And txtSchoolType.Text = "English" Then
601                 auto2()
602             End If
603             If txtClassType.Text =
"Higher Secondary" And txtSchoolType.Text = "English" Then
604                 auto3()
605             End If
606             If txtClassType.Text =
"Nursery" And txtSchoolType.Text = "Gujarati" Then
607                 auto4()
608             End If
609             If txtClassType.Text =
"Primary" And txtSchoolType.Text = "Gujarati" Then
610                 auto5()
611             End If
612             If txtClassType.Text =
"Secondary" And txtSchoolType.Text = "Gujarati" Then
613                 auto6()
614             End If
615             If txtClassType.Text =
"Higher Secondary" And txtSchoolType.Text = "Gujarati" Then
616                 auto7()
617             End If
618             con = New SqlConnection(cs)
619             con.Open()
620             Dim cb As String =
"insert into BusFeePayment_Student(BFP_ID, PaymentID, BusHolderID, Session,installment,TotalFee, DiscountPer, DiscountAmt, PreviousDue, Fine, GrandTotal, TotalPaid, ModeOfPayment, PaymentModeDetails, PaymentDate, PaymentDue, ClassType,SchoolType,Class,Section) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18,@d19,@d20)"
621             cmd = New SqlCommand(cb)
622             cmd.Connection = con
623             cmd.Parameters.AddWithValue(
"@d1", txtBFPId.Text)
624             cmd.Parameters.AddWithValue(
"@d2", txtFeePaymentID.Text)
625             cmd.Parameters.AddWithValue(
"@d3", txtBusHolderID.Text)
626             cmd.Parameters.AddWithValue(
"@d4", txtSession.Text)
627             cmd.Parameters.AddWithValue(
"@d5", cmbInstallment.Text)
628             cmd.Parameters.AddWithValue(
"@d6", txtBusFee.Text)
629             cmd.Parameters.AddWithValue(
"@d7", txtDiscountPer.Text)
630             cmd.Parameters.AddWithValue(
"@d8", txtDiscount.Text)
631             cmd.Parameters.AddWithValue(
"@d9", txtPreviousDue.Text)
632             cmd.Parameters.AddWithValue(
"@d10", txtFine.Text)
633             cmd.Parameters.AddWithValue(
"@d11", txtGrandTotal.Text)
634             cmd.Parameters.AddWithValue(
"@d12", txtTotalPaid.Text)
635             cmd.Parameters.AddWithValue(
"@d13", cmbPaymentMode.Text)
636             cmd.Parameters.AddWithValue(
"@d14", txtPaymentModeDetails.Text)
637             cmd.Parameters.AddWithValue(
"@d15", dtpPaymentDate.Value)
638             cmd.Parameters.AddWithValue(
"@d16", txtBalance.Text)
639             cmd.Parameters.AddWithValue(
"@d17", txtClassType.Text)
640             cmd.Parameters.AddWithValue(
"@d18", txtSchoolType.Text)
641             cmd.Parameters.AddWithValue(
"@d19", txtClass.Text)
642             cmd.Parameters.AddWithValue(
"@d20", txtSection.Text)
643             cmd.ExecuteNonQuery()
644             Dim st As String =
"added the new bus fee payment entry having payment id '" & txtFeePaymentID.Text & "'"
645             LogFunc(lblUser.Text, st)
646             MessageBox.Show(
"Successfully paid", "Fee", MessageBoxButtons.OK, MessageBoxIcon.Information)
647             btnSave.Enabled = False
648             con.Close()
649             Print()
650         Catch ex As Exception
651             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
652         End Try
653     End Sub
654
655     Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
656         Try
657             If MessageBox.Show(
"Do you really want to delete the record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Yes Then
658                 delete_records()
659             End If
660         Catch ex As Exception
661             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
662         End Try
663     End Sub
664     Private Sub delete_records()
665         Try
666             Dim RowsAffected As Integer =
0
667             con = New SqlConnection(cs)
668             con.Open()
669             Dim cq As String =
"delete from BusFeePayment_Student where ID= " & txtID.Text & ""
670             cmd = New SqlCommand(cq)
671             cmd.Connection = con
672             RowsAffected = cmd.ExecuteNonQuery()
673             If RowsAffected >
0 Then
674                 Dim st As String =
"deleted the bus fee payment entry having payment id '" & txtFeePaymentID.Text & "'"
675                 LogFunc(lblUser.Text, st)
676                 MessageBox.Show(
"Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
677                 Reset()
678                 Reset()
679             Else
680                 MessageBox.Show(
"No record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
681                 Reset()
682                 Reset()
683             End If
684             con.Close()
685         Catch ex As Exception
686             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
687         End Try
688     End Sub
689
690     Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click
691         If Len(Trim(txtAdmissionNo.Text)) =
0 Then
692             MessageBox.Show(
"Please retrieve bus holder info", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
693             txtAdmissionNo.Focus()
694             Exit Sub
695         End If
696         If Len(Trim(cmbInstallment.Text)) =
0 Then
697             MessageBox.Show(
"Please select installment", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
698             cmbInstallment.Focus()
699             Exit Sub
700         End If
701         If Len(Trim(txtFine.Text)) =
0 Then
702             MessageBox.Show(
"Please enter fine", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
703             txtFine.Focus()
704             Exit Sub
705         End If
706         If Len(Trim(cmbPaymentMode.Text)) =
0 Then
707             MessageBox.Show(
"Please select Payment Mode", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
708             cmbPaymentMode.Focus()
709             Exit Sub
710         End If
711         If Len(Trim(txtTotalPaid.Text)) =
0 Then
712             MessageBox.Show(
"Please enter total paid", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
713             txtTotalPaid.Focus()
714             Exit Sub
715         End If
716         If Val(txtBalance.Text) <
0 Then
717             MessageBox.Show(
"Balance is not possible less than zero", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error)
718             Exit Sub
719         End If
720         Try
721             
'con = New SqlConnection(cs)
722             
'con.Open()
723             
'Dim ct As String = "select PaymentDate from BusFeePayment_Student where AdmissionNo=@d1"
724             
'cmd = New SqlCommand(ct)
725             
'cmd.Connection = con
726             
'cmd.Parameters.AddWithValue("@d1", txtAdmissionNo.Text)
727             
'Dim da As New SqlDataAdapter(cmd)
728             
'Dim ds As DataSet = New DataSet()
729             
'da.Fill(ds)
730             
'If ds.Tables(0).Rows.Count > 0 Then
731             
'If dtpPaymentDate.Value.Date < ds.Tables(0).Rows(0)("PaymentDate") Then
732             
'MessageBox.Show("updating old record is not allowed when student has been already paid fee again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
733             
'End If
734             
'Exit Sub
735             
'End If
736             
'con.Close()
737             con = New SqlConnection(cs)
738             con.Open()
739             Dim cb As String =
"Update BusFeePayment_Student set BFP_ID=@d1, PaymentID=@d2, BusHolderID=@d3, Session=@d4, Installment=@d5,TotalFee=@d6, DiscountPer=@d7, DiscountAmt=@d8, PreviousDue=@d9, Fine=@d10, GrandTotal=@d11, TotalPaid=@d12, ModeOfPayment=@d13, PaymentModeDetails=@d14,PaymentDue=@d16, ClassType=@d17,SchoolType=@d18,Class=@d19,Section=@d20 where ID= " & txtID.Text & ""
740             cmd = New SqlCommand(cb)
741             cmd.Connection = con
742             cmd.Parameters.AddWithValue(
"@d1", txtBFPId.Text)
743             cmd.Parameters.AddWithValue(
"@d2", txtFeePaymentID.Text)
744             cmd.Parameters.AddWithValue(
"@d3", txtBusHolderID.Text)
745             cmd.Parameters.AddWithValue(
"@d4", txtSession.Text)
746             cmd.Parameters.AddWithValue(
"@d5", cmbInstallment.Text)
747             cmd.Parameters.AddWithValue(
"@d6", txtBusFee.Text)
748             cmd.Parameters.AddWithValue(
"@d7", txtDiscountPer.Text)
749             cmd.Parameters.AddWithValue(
"@d8", txtDiscount.Text)
750             cmd.Parameters.AddWithValue(
"@d9", txtPreviousDue.Text)
751             cmd.Parameters.AddWithValue(
"@d10", txtFine.Text)
752             cmd.Parameters.AddWithValue(
"@d11", txtGrandTotal.Text)
753             cmd.Parameters.AddWithValue(
"@d12", txtTotalPaid.Text)
754             cmd.Parameters.AddWithValue(
"@d13", cmbPaymentMode.Text)
755             cmd.Parameters.AddWithValue(
"@d14", txtPaymentModeDetails.Text)
756             cmd.Parameters.AddWithValue(
"@d16", txtBalance.Text)
757             cmd.Parameters.AddWithValue(
"@d17", txtClassType.Text)
758             cmd.Parameters.AddWithValue(
"@d18", txtSchoolType.Text)
759             cmd.Parameters.AddWithValue(
"@d19", txtClass.Text)
760             cmd.Parameters.AddWithValue(
"@d20", txtSection.Text)
761             cmd.ExecuteNonQuery()
762             con.Close()
763             Dim st As String =
"updated the bus fee payment entry having payment id '" & txtFeePaymentID.Text & "'"
764             LogFunc(lblUser.Text, st)
765             MessageBox.Show(
"Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
766             btnUpdate.Enabled = False
767             con.Close()
768         Catch ex As Exception
769             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
770         End Try
771     End Sub
772
773     Private Sub txtFine_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtFine.KeyPress
774         Dim keyChar = e.KeyChar
775
776         If Char.IsControl(keyChar) Then
777             
'Allow all control characters.
778         ElseIf Char.IsDigit(keyChar) OrElse keyChar =
"."c Then
779             Dim text = Me.txtFine.Text
780             Dim selectionStart = Me.txtFine.SelectionStart
781             Dim selectionLength = Me.txtFine.SelectionLength
782
783             text = text.Substring(
0, selectionStart) & keyChar & text.Substring(selectionStart + selectionLength)
784
785             If Integer.TryParse(text, New Integer) AndAlso text.Length >
16 Then
786                 
'Reject an integer that is longer than 16 digits.
787                 e.Handled = True
788             ElseIf Double.TryParse(text, New Double) AndAlso text.IndexOf(
"."c) < text.Length - 3 Then
789                 
'Reject a real number with two many decimal places.
790                 e.Handled = False
791             End If
792         Else
793             
'Reject all other characters.
794             e.Handled = True
795         End If
796     End Sub
797
798     Private Sub txtTotalPaid_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtTotalPaid.KeyPress
799         Dim keyChar = e.KeyChar
800
801         If Char.IsControl(keyChar) Then
802             
'Allow all control characters.
803         ElseIf Char.IsDigit(keyChar) OrElse keyChar =
"."c Then
804             Dim text = Me.txtTotalPaid.Text
805             Dim selectionStart = Me.txtTotalPaid.SelectionStart
806             Dim selectionLength = Me.txtTotalPaid.SelectionLength
807
808             text = text.Substring(
0, selectionStart) & keyChar & text.Substring(selectionStart + selectionLength)
809
810             If Integer.TryParse(text, New Integer) AndAlso text.Length >
16 Then
811                 
'Reject an integer that is longer than 16 digits.
812                 e.Handled = True
813             ElseIf Double.TryParse(text, New Double) AndAlso text.IndexOf(
"."c) < text.Length - 3 Then
814                 
'Reject a real number with two many decimal places.
815                 e.Handled = False
816             End If
817         Else
818             
'Reject all other characters.
819             e.Handled = True
820         End If
821     End Sub
822
823     Private Sub txtTotalPaid_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles txtTotalPaid.Validating
824         If Val(txtTotalPaid.Text) > Val(txtGrandTotal.Text) Then
825             MessageBox.Show(
"Total Pay can not be more than grand total", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
826             txtTotalPaid.Text =
""
827             txtTotalPaid.Focus()
828             Exit Sub
829         End If
830     End Sub
831
832     Private Sub txtFine_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtFine.TextChanged
833         Fill()
834     End Sub
835
836     Private Sub txtTotalPaid_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtTotalPaid.TextChanged
837         Fill()
838     End Sub
839
840     Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
841         Me.Close()
842     End Sub
843
844     Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnGetData.Click
845         frmBusFeePayment_StudentRecord.lblSet.Text =
"Bus Fee Payment"
846         frmBusFeePayment_StudentRecord.Reset()
847         frmBusFeePayment_StudentRecord.ShowDialog()
848     End Sub
849      Sub fillInstallment()
850         Try
851             con = New SqlConnection(cs)
852             con.Open()
853             Dim ct As String =
"SELECT distinct RTRIM(Installment) FROM Installment_Bus where Location=@d1"
854             cmd = New SqlCommand(ct)
855             cmd.Parameters.AddWithValue(
"@d1", txtLocation.Text)
856             cmd.Connection = con
857             rdr = cmd.ExecuteReader()
858             cmbInstallment.Items.Clear()
859             While rdr.Read
860                 cmbInstallment.Items.Add(rdr(
0))
861             End While
862             con.Close()
863         Catch ex As Exception
864             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
865         End Try
866     End Sub
867     Private Sub frmBusFeePayment_Student_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
868         fillInstallment()
869     End Sub
870
871   
872     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
873         Cursor = Cursors.Default
874         Timer1.Enabled = False
875     End Sub
876
877     Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
878         Print()
879     End Sub
880 End Class


Gõ tìm kiếm nhanh...